package de.baumann.browser.activitys.gg

import android.content.Context
import android.content.Intent
import android.os.Bundle
import de.baumann.browser.R
import de.baumann.browser.adapter.PagerAdapter
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.db.ETHWallet
import de.baumann.browser.fragments.gg.MineMortgageRecordsFragment
import de.baumann.browser.fragments.gg.MiningRecordsFragment
import de.baumann.browser.iview.gg.IMySmelterView
import de.baumann.browser.present.gg.MySmelterPresenter
import kotlinx.android.synthetic.main.activity_my_mortgage.*
import kotlinx.android.synthetic.main.include_tool_bar.*

class MySmelterActivity : BaseOdinActivity<IMySmelterView, MySmelterPresenter>(), IMySmelterView {

    companion object {
        fun startMySmelterActivity(context: Context, id: String,wallet:ETHWallet) {
            context.startActivity(Intent(context, MySmelterActivity::class.java).apply {
                putExtra("id", id)
                putExtras(Bundle().apply {
                    putSerializable("wallet",wallet)
                })
            })
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_my_smelter
    }

    override fun getTitleText(): String {
        return "My smelter"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        val fragment = MineMortgageRecordsFragment.instance
        val f2 = MiningRecordsFragment.instance
        val bundle = Bundle().apply {
            putString("id", intent.getStringExtra("id"))
            putSerializable("wallet",getWallet())
        }
        fragment.arguments = bundle
        f2.arguments = bundle
        val fragments = arrayListOf(fragment, f2)

        mortgagePager.adapter = PagerAdapter(supportFragmentManager, fragments, arrayOf("Mortgage records", "Mining records"))
        mortgageTab.setupWithViewPager(mortgagePager)
    }

    override fun initData() {
        presenter?.a03(intent.getStringExtra("id"),getWallet().address)
    }

    override fun createPresenter(): MySmelterPresenter {
        return MySmelterPresenter()
    }

    override fun createView(): IMySmelterView {
        return this
    }

    private fun getWallet():ETHWallet{
        return intent.getSerializableExtra("wallet") as ETHWallet
    }

    override fun x(x: String) {
        xxx.text = x
    }

    override fun y(y: String) {
        yyy.text = y
    }


}